// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-5-24

#include "stdafx.h"
#include ".\progress.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//##ModelId=44C4B6030033
CJoyProgressBar::CJoyProgressBar(void)
{
    m_progress = 0;
    m_side = 3;
	m_skinArea=true;
    
}

//##ModelId=44C4B603003E
CJoyProgressBar::~CJoyProgressBar(void)
{
}

//##ModelId=44C4B6030045
void CJoyProgressBar::SetImage(PCTSTR pszImageName)
{
    if(pszImageName == NULL)
    {
        m_image = NULL;
        return;
    }
	
    m_image = JoyGetManager()->CreateImage(pszImageName);

	
	
}
//##ModelId=44C4B6030050
void CJoyProgressBar::SetStartEnd()
{
	m_progressStart=(m_side/m_image->GetWidth())*100;
	m_progressEnd=(m_image->GetWidth()-2*m_side)/m_image->GetWidth()*100;
	
    InvalidateCtrl();
}

//##ModelId=44C4B603004E
void CJoyProgressBar::Side(UINT s)
{
    m_side = s;
    InvalidateCtrl();
}

//##ModelId=44C4B6030041
void CJoyProgressBar::Progress(UINT p)
{
    m_progress = p;
    InvalidateCtrl();
}

//##ModelId=44C4B6030030
void CJoyProgressBar::CM_Draw(Graphics& graph)
{
    if(m_image == NULL)
    {
        return;
    }
   
	INT start = m_side;
	INT end = (m_area.Width()-2*m_side)*m_progress/100;
	int imgEnd = m_image->GetWidth()-start;
    
	graph.DrawImage(m_image, Rect(m_area.left, 0, m_side, m_area.Height()),
        0, 0, m_side, m_image->GetHeight(), UnitPixel);
	
	TextureBrush backBrush(m_image, WrapModeTile, RectF((REAL)start, 0, (REAL)imgEnd-start, (REAL)m_image->GetHeight()));
	graph.FillRectangle(&backBrush, Rect(m_area.left+start, 0, end, m_image->GetWidth()));
	
	graph.DrawImage(m_image, Rect(m_area.left+start+end, 0, m_side, m_image->GetWidth()),
     imgEnd, 0, m_side, m_image->GetHeight(), UnitPixel);

   
}
//##ModelId=44C4B6030021
void CJoyProgressBar::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);
	 CJoyXmlAttribute* pImageAttrib = pSkinElem->FindAttribute("image");
    if(pImageAttrib != NULL)
    {
        if(!pImageAttrib->m_value.IsEmpty())
        {
            SetImage(pImageAttrib->m_value);
        }
    }

  
}
